#!/bin/bash

path=~/software
if [ ! -d $path ]; then
    mkdir $path
else
    echo $path exist
fi

if [ -f "jdk1.8"* ]; then
    tar -zxvf jdk*
    cp -r jdk1*/ $path/jdk1*/
    cd $path/jdk1*
    home=$(pwd)

    echo $home
    echo "export JAVA_HOME=${home}" >>/etc/profile
    echo "export JRE_HOME=\$JAVA_HOME/jre" >>/etc/profile
    echo "export CLASSPATH=\$JAVA_HOME/lib" >>/etc/profile
    echo "export PATH=\$PATH:\$JAVA_HOME/bin" >>/etc/profile

    source /etc/profile
    echo "complete!"
else
    echo "file not found!"
fi
#输出java版本号
echo "java version:"
echo $(java -version 2>&1 | awk 'NR==1{gsub(/"/,"");print $3}')